<template>
  <div class="reportMistakeInfoAction el-card is-always-shadow el-card__body">
    <avue-crud
      ref="crud"
      :option="option"
      :table-loading="listLoading"
      :data="tableData"
      :page.sync="page"
      :search.sync="searchForm"
      @search-change="handleFilter"
      @selection-change="selectionChange"
      @on-load="search">
      <template slot="menuRight">
        <el-button type="primary" size="mini" @click="openDuiZhang">提交对账</el-button>
      </template>
      <template slot-scope="scope" slot="lineCodeSearch">
        <el-select v-model="searchForm.lineCode" placeholder="请选择" style="width: 150px" @change="changeLine" >
          <el-option
            v-for="(item,index) in lineCodes"
            :key="index"
            :label="item.name"
            :value="item.code">
          </el-option>
        </el-select>
      </template>
      <template slot-scope="scope" slot="stationCodeSearch">
        <el-select v-model="searchForm.stationCode" placeholder="请选择" style="width: 150px" @change="changeStation">
          <el-option
            v-for="(item,index) in stationCodes"
            :key="index"
            :label="item.name"
            :value="item.code">
          </el-option>
        </el-select>
      </template>

      <template slot-scope="scope" slot="submitTimeSearch">
        <el-date-picker
          v-model="searchForm.submitTime"
          type="month">
        </el-date-picker>
      </template>
      <template slot-scope="scope" slot="submitCreatorNameSearch">
          <el-select v-model="searchForm.submitCreatorName" placeholder="请选择" style="width: 150px" >
            <el-option
              v-for="(item,index) in conductorPersonNames"
              :key="index"
              :label="item.username"
              :value="item.username">
            </el-option>
          </el-select>
      </template>
      <template slot="searchMenu" slot-scope="{row,size}">
        <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm)}" icon="el-icon-delete">清空</el-button>
      </template>
    </avue-crud>
    <submit ref="submit" v-if="isShowDia"></submit>
  </div>
</template>


<script>
    import {getForm, postForm} from '@/api/gen/gen';
    import submit from './submit';
    import {
      getgetStationCodes,
      getLineCodes, getLineName, getPersonRole, getStationName, setSearchFiledsEmpty
    } from "../../../api/subwayRat/commonCheck";
    import {getSwAuDataSubmitList} from "../../../api/subwayRat/shouRuShenheSJTJ";
    export default {
      components:{
        submit
      },
      data() {
            return {
              row : {},
              listLoading: true,
              fileTemp:{},
              searchForm:{
                lineCode:'',
                stationCode:''
              },
              tableData:[],
              page: {
                total: 0, // 总页数
                currentPage: 1, // 当前页数
                pageSize: 20, // 每页显示多少条,
                isAsc: false// 是否倒序
              },
              isShowDia:false,
              autoWidth: true,
              downloadLoading: false,
              isShowReportMistakeInfoEditor:false,//是否加载编辑页面
              isShowReportMistakeInfoPreview:false,//是否加载预览页面
              multipleSelectionRows:[],
              multipleSelectionKeys:[],
              lineCodes:[],
              stationCodes:[],
              conductorPersonNames:[],
              param:{
                lineCode:"",
                stationCode:'',
                reprotTime:"",
                reportNameId:"",
                settleBeginTime:"",
                settleEndTime:""
              },
              option:{
                emptyBtn:false,
                editBtn:false,
                delBtn:false,
                addBtn:false,
                border: true,
                index:true,
                indexLabel:'序号',
                page:true,
                align:'center',
                menu:false,
                menuWidth:150,
                menuAlign:'center',
                selection: true,
                reserveSelection:true,
                column:[
                  {prop:"lineCode", label:"线路",type:'select',search:true,searchslot:true,formatter:function (row,v) {
                      return getLineName(v);
                    }},
                  {prop:"stationCode", label:"车站",search:true,searchslot:true,formatter:function (row,v) {
                      return getStationName(row.lineCode,v);
                    }},
                  {prop:"beginTime" ,label:"数据开始时间"},
                  {prop:"endTime", label:"数据结束时间"},
                  {prop:"submitTime",label:"提交时间",search:true,searchslot:true},
                  {prop:"submitCreatorName", label:"提交人",search:true,searchslot:true}
                  ]
              },
            }
        },
        created() {
          if(this.$route.query.row){
            this.row = this.$route.query.row;
            debugger
            if(!this.row.submitLineCode && ! this.row.submitStationCode){
              this.row.submitLineCode = this.row.lineCode;
              this.row.submitStationCode = this.row.stationCode;
            }
            this.addContent('添加',0);
          }
        },
        methods: {
        setSearchFiledsEmpty,
          openDuiZhang(){
          if(this.multipleSelectionRows.length<=0){
            this.$message.warning("请选择数据据");
            return;
          }
            this.isShowDia=true;
            this.$nextTick(()=>{
              this.$refs.submit.show(this.multipleSelectionRows);
            })
          },
          search(){
            Object.assign(this.searchForm,this.page);
            this.searchForm.userCode=this.$store.getters.userInfo.userCode;
            getSwAuDataSubmitList(this.searchForm).then((res)=>{
              this.tableData=res.data.data;
              this.listLoading = false;
              this.page.total=res.data.total;
            });
          },
          initLine(){
            getLineCodes().then(res=>{ //获取线路
              this.lineCodes=res;
            });
          },
          changeLine(v){
            getgetStationCodes(v).then(res=>{
              this.stationCodes=res;
              this.searchForm.stationCode='';
            })
          },
          changeStation(v){
            getPersonRole({roleCode:'SPY',stationCode:v}).then((res)=>{
              this.conductorPersonNames=res.data.data;
            });
          },
          selectionChange(list){
            this.multipleSelectionRows=list;
            this.multipleSelectionKeys=[];
            for(let i=0;i<list.length;i++){
              this.multipleSelectionKeys.push(list[i].id);
            }
          },
          handleFilter(params, done) {
            Object.assign(this.searchForm,params);
            this.search()
            done()
          },
        },
      mounted() {
        this.search();
        this.initLine();
      }
    }
</script>
<style lang="scss">

</style>
